<template>
  <div class="wrapper wrapper-content animated fadeInRight v-cloak" v-cloak>
    <div class="row">
      <div class="col-md-12">
        <a @click="edit('权限设置',{})" class="label label-success" href="javascript:" v-show='staff.hasPermission("user:edit:role")'><i class="fa fa-edit"></i> 新增角色</a>
        <div class="table-responsive table-scrollable">
          <table class="table table-bordered table-striped  table-hover">
            <thead>
            <tr>
              <th style="width:20px;">#</th>
              <th>角色名称</th>
              <th>创建时间</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody v-if="result.dataCount>0">
            <tr v-for="(item, index) in result.data">
              <td>{{(result.pageIndex-1) * result.pageSize + index+1}}</td>
              <td>{{item.name}}</td>
              <td>{{item.dateCreated | date('yyyy-MM-dd HH:mm:ss')}}</td>
              <td>
                <a @click="edit('权限设置',item)" class="label label-success" href="javascript:" v-show='staff.hasPermission("user:edit:role")'><i class="fa fa-edit"></i> 角色授权</a>
                <a @click="userlist(item)" class="label label-info" href="javascript:" v-show='staff.hasPermission("user:edit:role")'><i class="fa fa-user-secret"></i> 已有账号</a>
              </td>
            </tr>
            </tbody>
            <tbody v-else>
            <tr>
              <td colspan="4">
                <div class="alert"><strong>{{ result | message }}</strong></div>
              </td>
            </tr>
            </tbody>
          </table>
          <div class="b_page" v-html="tagPages"></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
  import '@/assets/css/style.css'

  import $ from '@/assets/js/jquery-vendor.js'
  import axios from 'axios'
  import '@/assets/js/datepicker-vendor.js'
  import {$storage, axiosContentType, site} from '@/assets/js/boss'
  import '@/assets/js/pageTag'

  export default {
    data() {
      return {
        result: {data: {pageIndex: 1, data: []}, message: ''},
        tagPages: ''
      }
    },
    mounted() {
      let that = window.$vueApp = this;
      document.getElementsByTagName('body')[0].className = 'fixed-sidebar full-height-layout';
      this.staff.init(function () {
        that.page();
      });
      $('.input-daterange').datepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd',
        keyboardNavigation: !1,
        forceParse: !1,
        autoclose: !0
      });
    },
    methods: {
      page(pageIndex) {
        let that = this;
        if (!pageIndex) pageIndex = 1;
        axios.post(site.authRole.page + pageIndex
          , $('#info_search_form').serialize()
          , axiosContentType.xWwwFormUrlencoded
        ).then(function (response) {
          const result = response.data;
          if (result.code === 0) {
            that.result = result.data;
            that.tagPages = that.tag.page(result.data);
          } else {
            alert(result.message);
          }
        });
      },
      edit(title, item) {
        $storage.setItem(site.authRole.info, item.id || 0);
        this.lbox.openMyBoxLayer(title, site.authRole.view + '/edit');
      },
      userlist(item) {
        $storage.setItem(site.authRole.info, item.id || 0);
        this.lbox.openMyBoxLayer(`角色[${item.name}]-已有账号`, site.authRole.view + '/user');
      }
    }
  }
</script>
